package com.langsheng.lsintell.ui.activity;

import android.Manifest;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat;

import kr.co.namee.permissiongen.PermissionFail;
import kr.co.namee.permissiongen.PermissionGen;
import kr.co.namee.permissiongen.PermissionSuccess;

/**
 * Created by xxw on 2017/2/25.
 */

public class LSSplashActivity extends LSBaseActivity implements ActivityCompat.OnRequestPermissionsResultCallback {

    private final static int permissionRequestCode = 101;
    private String[] needPermission = new String[]{
            Manifest.permission.ACCESS_COARSE_LOCATION,
            Manifest.permission.ACCESS_FINE_LOCATION,
            Manifest.permission.WRITE_EXTERNAL_STORAGE,
            Manifest.permission.READ_PHONE_STATE,
            Manifest.permission.CAMERA
    };


    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        PermissionGen.onRequestPermissionsResult(this, requestCode, permissions, grantResults);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        PermissionGen.needPermission(this, permissionRequestCode, needPermission);
    }


    private Runnable startMain = new Runnable() {
        @Override
        public void run() {
            Intent intent = new Intent(LSSplashActivity.this, LSMainActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
            startActivity(intent);
            finish();
        }
    };

    @PermissionFail(requestCode = permissionRequestCode)
    private void AccessFailed() {
        handler.postDelayed(startMain, 500);
    }

    @PermissionSuccess(requestCode = permissionRequestCode)
    private void accessSuccess() {
        handler.postDelayed(startMain, 500);
    }

}
